.PHONY: build serve
BUILD_COMMAND=./build
GITBUILD_COMMAND=./gitbuild
WEBSERVER_COMMAND=mkdir -p dist && cd dist && ruby -run -ehttpd . -p8000
WEBSERVER_KILL_COMMAND=killall ruby

USER_AT_SERVER=$(shell cat ~/.user_at_server)

default:
	$(MAKE) -j2 build serve

build:
	$(BUILD_COMMAND) || true
	$(WEBSERVER_KILL_COMMAND) || true
	@inotifywait -e modify -r src || true
	$(MAKE) build

oneshot:
	echo "Oneshot building"
	$(BUILD_COMMAND)

serve:
	$(WEBSERVER_COMMAND) || true
	$(MAKE) serve

deploy:
	@rsync --exclude trigger -e "ssh -o StrictHostKeyChecking=no" -avh --delete dist/ $(USER_AT_SERVER):/home/public/milesalan.com

deps:
	gem install redcarpet rouge nokogiri rouge webrick

docker_image:
	docker build -t ma .

docker_dev: docker_image
	docker run -v $(shell pwd)/dist:/site/dist -v $(shell pwd)/src:/site/src -v $(shell pwd)/gitsrc:/site/gitsrc --net host -it --rm --name ma ma make default

docker_oneshot: docker_image
	docker run -v $(shell pwd)/dist:/site/dist -v $(shell pwd)/src:/site/src -v $(shell pwd)/gitsrc:/site/gitsrc --net host -it --rm --name ma ma make oneshot

docker_shell:
	docker run -v $(shell pwd)/dist:/site/dist -v $(shell pwd)/src:/site/src -v $(shell pwd)/gitsrc:/site/gitsrc --net host -it --rm --name ma ma sh
